package StudentManage;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

/**
 * @Auther: MFM
 * @Date: 2021/7/24 - 07 - 24 - 16:07
 * @version: 1.0
 */

public class HashSetDemo {

    public static void main(String[] args) throws Exception {
        /*
            使用HashSet一定是利用它的不可重复特性
         */
        Random random = new Random();
        Set<Integer> set = new HashSet<>();

        //数据生成中奖号码 set
        while (set.size() < 7) {
            Integer value = random.nextInt(33) + 1;
            set.add(value);
        }

        int totalMoney = 0;
        //随机生成 五张彩票
        for (int i = 0; i < 1000; i++) {
            Set<Integer> set1 = new HashSet<>();
            while (set1.size() < 7) {
                Integer value = random.nextInt(33) + 1;
                set1.add(value);
            }

            int times = 0;

            for (Integer integer : set1) {
                for (Integer integer1 : set) {
                    if (integer.equals(integer1)) {
                        times++;
                    }
                }
            }

            int[] money = {2, 5, 10, 100, 200, 1000, 10000};
            if (times!=0){
                totalMoney += money[times - 1];
            }


            if (times == 0) {
                System.out.println("谢谢惠顾，您第" + (i + 1) + "张彩票未中奖");
            } else if (times == 7) {
                System.out.println("恭喜您，第" + (i + 1) + "张彩票中了特等奖");
            } else {
                System.out.println("第" + (i + 1) + "张彩票中了" + (7 - times) + "等奖");
            }

        }
        System.out.println("一共赢了"+totalMoney+"元");
    }
}
